<cfcomponent output="false">
	
	<!--- --->
	
	<cffunction name="saveUser" access="public" output="true" returntype="void">
		<cfargument name="user_id" required="true" />
		
		#application#

	</cffunction>
	
	<!--- --->
	
	<cffunction name="createAccount" access="public" output="true" returntype="string">
		<cfargument name="email" required="true" />
		<cfargument name="password" required="true" />
		<cfargument name="first_name" required="true" />
		<cfargument name="last_name" required="true" />
		<cfargument name="middle_name" required="false" default="" />
		<cfargument name="street_1" required="false" default="" />
		<cfargument name="street_2" required="false" default="" />
		<cfargument name="city" required="false" default="" />
		<cfargument name="state_id" required="false" default="" />
		<cfargument name="zip" required="false" default="" />
			
		<cfset var local = {} />
		
		<cfset structDelete(arguments,"password2") />
		<cfset structDelete(arguments,"email2") />
		
		<cfquery name="local.dupeCheck" datasource="fundrdb">
			select id from user where email = '#arguments.email#'
			and active = 1
		</cfquery>
		
		<cfif local.dupeCheck.recordcount gt 0>
			<cfset session.message = "Account already exists for '#arguments.email#'" />
			<cfset session.userID = -1 />
			<cfset local.id = -1 />
		<cfelse>
			<!--- new ID --->
			<cfset local.id = application.q.dbsave(table="user",id="",argumentCollection=arguments) />

			<cfset session.userID = local.id />
			<cfset application.q.addMessage("User Created Successfully.") />
		</cfif>
		
		<cfreturn local.id />

	</cffunction>
	
	<!--- --->
	
	<cffunction name="getUserByID" access="public" output="true" returntype="query">
		<cfargument name="userID" required="true" />
		<cfargument name="refresh" required="false" default="false" />
		
		<cfset var local = {} />
		
		<!--- get user from session instead of database --->
		<cfif structKeyExists(session,"user") and not arguments.refresh and session.user.recordcount gt 0 and session.userID neq "-1">
			<cfset local.user = session.user />
		<cfelse>
			<cfset local.user = application.g.userGateway.getUserByID(arguments.userID) />
		</cfif>

		<cfreturn local.user />
			
	</cffunction>
	
	<!--- --->
	
	<cffunction name="getUserByEmail" access="public" output="true" returntype="query">
		<cfargument name="email" required="true" />

		<cfreturn application.g.userGateway.getUserByEmail(arguments.email) />
			
	</cffunction>
	
	<!--- --->

</cfcomponent>